home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.ada,comp.lang.c
- Subject: Re: C/C++ knocks the crap out of Ada
- Date: 11 Mar 1996 08:52:24 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4i1lo8INNf82@keats.ugrad.cs.ubc.ca>
- References: <TANMOY.96Mar9095253@qcd.lanl.gov> <Do40oA.2EJ.0.-s@inmet.camb.inmet.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <Do40oA.2EJ.0.-s@inmet.camb.inmet.com>,
- Tucker Taft <stt@houdini.camb.inmet.com> wrote:
- >Tanmoy Bhattacharya (tanmoy@qcd.lanl.gov) wrote:
- >: ...
- >: And by the way, from my experience, the most common kind of errors are
- >: not those that can be statically or dynamically `checked'. I did
- >: occasionally have off by one errors leading to array bound violations,
- >: but, by far, the more important kinds of errors were what one would
- >: call `logic errors'. What I wrote made sense, and probably would have
- >: made sense in every language I expressed myself, but it was not what I
- >: wanted to code. ...
- >
- >I have heard this comment many times from people who have never
- >used a compiler (like every Ada compiler) that inserts run-time
- >consistency checks. However, once you use such a compiler, the
- >empirical evidence is that consistency checks *do* catch many logic
- >errors. The basic reason is that an "illogical" program is in most cases
- >also "inconsistent" at the low level. For example, if you declare
- >a subtype to have the range 0..30, an illogical program will often
- >end up producing a value outside this range.
-
- Ah yes; this is one thing I miss when working with C. That _can_ catch a lot of
- errors, and I use such range types whenever they are available in a language
- for array indices and all kinds of bounded values.
-
- >This is most easily demonstrated by experience. It is not easy to
- >convince someone who has never tried such a compiler. You seem
- >open to giving one a try, and I encourage you to do so.
-
- I can't speak for Tanmoy, but I have used such featuers, having done quite a
- bit of Modula-2 coding once upon a time. Such range checks can help greatly,
- but again, they are not all powerful.
-
- Recently, I had a good laugh when the 'p2c' compiler translated a Pascal 1..100
- integer type into a C unsigned char.
-
- The closest thing you can do for checking ranges and other conditions in
- standard C is use the <assert.h> facility, which is ugly, and requires
- discipline to use. It does get you the results if you apply it consistently,
- but it's nothing like having a compiler _know_ what the range of an integer
- ought to be and automatically generate a check when given the option.
- --
-
-